﻿@model Sharp.WebBooter.Areas.CMS.Models.UserGroupViewModel

<section class="content-header">
    <h1>
        编辑用户组
    </h1>
    <ol class="breadcrumb">
        <li><a href="@Url.Action("Index", "Home")"><i class="fa fa-home"></i> 首页</a></li>
        <li>用户</li>
        <li class="active">用户组管理</li>
    </ol>
</section>

<section class="content" id="mm">
    <section class="scrollable padder-sm p-t-sm">
        <section class="panel panel-default no-borders">
            <header class="panel-heading">用户组</header>
            <ul class="nav nav-tabs tab-header">
                <li class="active">
                    <a href="#jibenxinxi" data-toggle="tab" class="m-l">基本信息</a>
                </li>
                <li id="glry">
                    <a href="#guanlirenyuan" data-toggle="tab">包含用户</a>
                </li>

            </ul>
            <div class="tab-content">
                <div class="tab-pane wrapper-sm active" id="jibenxinxi">
                    <div id="modalcontent">
                        @using (Html.Bootstrap().BeginForm(c => c.Horizontal()))
                        {
                            @Html.ValidationSummary()
                            <div class="form-group">
                                @Html.LabelFor(m => m.Title, new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    @Html.Bootstrap().TextBoxFor(m => m.Title)
                                </div>
                            </div>

                            <div class="form-group">
                                @Html.LabelFor(m => m.Remark, new { @class = "col-sm-2 control-label" })
                                <div class="col-sm-10">
                                    @Html.Bootstrap().TextareaFor(m => m.Remark)
                                </div>
                            </div>
                            @Html.HiddenFor(x => x.Id)
                        }
                    </div>
                    <div class="modal-footer text-center">
                        @Html.Bootstrap().Button("保存").Style(BootstrapStyle.Primary).Click("window.app.saveForm(event,'" + @Url.Action("Save") + "');").Ico(IcoType.Save)
                        @Html.Bootstrap().Button("返回").Style(BootstrapStyle.Default).Click("window.app.loadUI('" + @Url.Action("Index") + "');").Ico(IcoType.Back)
                    </div>
                </div>
                <div class="tab-pane wrapper-sm" id="guanlirenyuan">
                    <div class="wrapper-sm-15 ribbon">
                        <a data-toggle="ajaxModal" href="@Url.Action("UserDialog", new { userGroupId = "" + @Model.Id + "" })" class="btn btn-default">
                            <i class="fa fa-plus fa-fw"></i>
                            <span>添加</span>
                        </a>
                        <a href="javascript:UnRelationUser('@Url.Action("UnRelationUser", new { userGroupId = "" + @Model.Id + "" })')" class="btn btn-default">
                            <i class="fa fa-times fa-fw"></i>
                            <span>删除</span>
                        </a>
                    </div>
                    <div class="table-responsive">
                        <table id="selectedUsers" width="100%" class="table table-bordered table-striped table-condensed table-hover"></table>
                    </div>
                </div>
            </div>
        </section>
    </section>
</section>


<script>
    $(function () {
        $('#selectedUsers').dataTable({
            "serverSide": true,
            "ajax": {
                "url": "@Url.Action("GetPaged", "User")",
                "type": "POST",
                "data": {
                    userGroupId: $("#Id").val()
                }
            },
            "columnDefs": [
                 { sDefaultContent: '', aTargets: ['_all'] }
            ],
            columns: [
                { title: '<label class="checkbox i-checks"><input type="checkbox" /><i></i></label>', data: function (row, type, set) { return '<label class="checkbox i-checks"><input type="checkbox" name="cellCheckbox" value="' + row.id + '" /><i></i></label>'; }, "bStorable": false, width: 30 },
                { title: '账号', data: 'userName', width: 70, "sClass": "center" }

            ]
        });
    });
    UnRelationUser = function (url) {
        var userIds = new Array();
        $("#selectedUsers tbody tr").each(function (x) {
            var checkbox = $(this).find("td:eq(0) input");
            if (checkbox.length > 0 && checkbox.prop('checked')) {
                userIds.push(checkbox.val());
            }
        });

        if (userIds.length === 0) {
            window.app.message("请选中一项。");
            return;
        }

        swal({
            title: "请确认是否删除？",
            text: "您正在进行删除操作，该操作不可逆!",
            type: "warning",
            showCancelButton: true,
            confirmButtonClass: "btn-danger"
        }).then(function (isConfirm) {
            if (isConfirm === true) {
                $.ajax({
                    type: "POST",
                    url: url,
                    data: { "userIds": userIds },
                    dataType: "json",
                    success: function (data) {
                        if (data.Err.length > 0) {
                            swal("出错啦！", data.Err, "error");
                        }
                        else {
                            swal("已经删除", "删除成功！", "success");
                            $("#selectedUsers").DataTable().ajax.reload();
                        }
                    }
                });
            }
        });

    }
</script>